﻿using Md.Api.Model;
using Md.Api.Model.Manage.SysMenu.Request;
using Md.Api.Service.Manage.SysMenu;
using Microsoft.AspNetCore.Mvc;

namespace Md.Api.Controllers.Manage;
/// <summary>
/// 系统菜单
/// </summary>
[ApiController]
[Produces("application/json")]
[Route("md-api/manage/system/menu")]
public class SysMenuController : ControllerBase
{
    /// <summary>
    /// 通过菜单编号删除系统菜单服务
    /// </summary>
    public DeleteSysMenuByMenuIdService deleteSysMenuByMenuIdService { get; set; }
    /// <summary>
    /// 通过菜单编号删除系统菜单
    /// </summary>
    /// <param name="menuIds">菜单编号多个逗号分割（1,2,3...）</param>
    /// <param name="signModel">加密实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpDelete("{menuIds}")]
    public async Task<ResponseMessageModel> DeleteSysMenuByMenuId(string menuIds, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestDeleteSysMenuByMenuIdModel();

        model.MenuIds = menuIds;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => deleteSysMenuByMenuIdService.Execute(model));
    }

    /// <summary>
    /// 添加系统菜单服务
    /// </summary>
    public InsertSysMenuService insertSysMenuService { get; set; }
    /// <summary>
    /// 添加系统菜单
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpPost]
    public async Task<ResponseMessageModel> InsertSysMenu([FromBody] RequestInsertSysMenuModel model)
    {
        return await Task.Run(() => insertSysMenuService.Execute(model));
    }

    /// <summary>
    /// 通过菜单编号更新系统菜单服务
    /// </summary>
    public UpdateSysMenuByMenuIdService updateSysMenuByMenuIdService { get; set; }
    /// <summary>
    /// 通过菜单编号更新系统菜单
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpPut]
    public async Task<ResponseMessageModel> UpdateSysMenuByMenuId([FromBody] RequestUpdateSysMenuByMenuIdModel model)
    {
        return await Task.Run(() => updateSysMenuByMenuIdService.Execute(model));
    }

    /// <summary>
    /// 通过菜单编号获取系统菜单服务
    /// </summary>
    public GetSysMenuByMenuIdService getSysMenuByMenuIdService { get; set; }
    /// <summary>
    /// 通过菜单编号获取系统菜单
    /// </summary>
    /// <param name="menuId">菜单编号</param>
    /// <param name="signModel">加密实体</param>
    /// <returns>ResponseMessageModel</returns>
    [HttpGet("{menuId}")]
    public async Task<ResponseMessageModel> GetSysMenuByMenuId(long menuId, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestGetSysMenuByMenuIdModel();

        model.MenuId = menuId;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => getSysMenuByMenuIdService.Execute(model));
    }

    /// <summary>
    /// 获取系统菜单列表服务
    /// </summary>
    public GetSysMenuListService getSysMenuListService { get; set; }
    /// <summary>
    /// 获取系统菜单列表
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("list"), HttpPost]
    public async Task<ResponseMessageModel> GetSysMenuList([FromBody] RequestGetSysMenuListModel model)
    {
        return await Task.Run(() => getSysMenuListService.Execute(model));
    }

    /// <summary>
    /// 分页获取系统菜单列表服务
    /// </summary>
    public GetSysMenuPageListService getSysMenuPageListService { get; set; }
    /// <summary>
    /// 分页获取系统菜单列表
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("listPage"), HttpPost]
    public async Task<ResponseMessageModel> GetSysMenuPageList([FromBody] RequestGetSysMenuPageListModel model)
    {
        return await Task.Run(() => getSysMenuPageListService.Execute(model));
    }

    /// <summary>
    /// 获取系统菜单树列表服务
    /// </summary>
    public GetSysMenuTreeListService getSysMenuTreeListService { get; set; }
    /// <summary>
    /// 获取系统菜单树列表
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("treeList"), HttpPost]
    public async Task<ResponseMessageModel> GetSysMenuTreeList([FromBody] RequestGetSysMenuListModel model)
    {
        return await Task.Run(() => getSysMenuTreeListService.Execute(model));
    }

    /// <summary>
    /// 通过用户获取系统菜单树列表服务
    /// </summary>
    public GetSysMenuTreeListByUserService getSysMenuTreeListByUserService { get; set; }
    /// <summary>
    /// 通过用户获取系统菜单树列表
    /// </summary>
    /// <param name="model">请求实体</param>
    /// <returns>ResponseMessageModel</returns>
    [Route("treeList/{userId}"), HttpGet]
    public async Task<ResponseMessageModel> GetSysMenuTreeListByUser(long userId, [FromQuery] RequestSignModel signModel)
    {
        var model = new RequestGetSysMenuTreeListByUserModel();

        model.UserId = userId;
        model.TimesTamp = signModel.TimesTamp;
        model.Mac = signModel.Mac;
        model.Ip = signModel.Ip;
        model.Sign = signModel.Sign;
        model.Version = signModel.Version;
        model.Token = signModel.Token;

        return await Task.Run(() => getSysMenuTreeListByUserService.Execute(model));
    }
}

